//可以传createName查询
let { datas } = require("./data_shema.js");
module.exports = {
    getData: async function (req, res, err) {
        let query = req.query;
        let findData = query.user ? { user:query.user } : {};
        let len = await datas.countDocuments(findData);
        let pages = Math.ceil(Number(len) / Number(query.limit));
        datas.find(
            findData,
            { passwd: false },
            {
                sort: { createTime: -1 },
                limit: Number(query.limit),
                skip: Number(query.limit) * (Number(query.page) - 1)
            }
        ).then((data) => {
            res.send({
                data: data,
                total: Number(len),
                pages: Number(pages),
                limit: Number(query.limit),
                page:Number(query.page)
            });
        })
    }
}